// pages/home/components/modelstyle/dongyi/dongyi.js
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    skulist1:[
      {
        src:"https://files.dianlinet.com/dianli/images/2021-09-16/16-53-22.jpg"
      },
      {
        src:"https://files.dianlinet.com/dianli/images/2021-09-16/16-54-51.jpg"
      },
      {
        src:"https://files.dianlinet.com/dianli/images/2021-09-16/16-55-21.jpg"
      }
    ],
    White_bg:true,
  },
  attached() {

  this.banner();
    app.func.getPromise('/list/shortcut')
        .then(([code, res]) => {
            this.setData({brand: res.data});
            console.log(res.data)
        });
       app.func.getPromise('/list/zone')
    .then(([code, res]) => {
        this.setData({zone: res.data});
        console.log(res)
        
        let arr =[]
        
        this.data.zone.forEach((item,index) =>{
         
          arr.push(item.sku)
          this.setData({
            sku:arr
          });
        })
    })
   
    
        app.func.getPromise('/categoriesv2')
            .then(([code, res]) => {
                console.log(res);
                if (code == 200) {
                  
                    this.Cart = res.data;
                    let leftmun = this.Cart.map(v => v.name);
                    let currentIndex = 0;
                    
                    // for(let i = 0; i < this.Cart.length;i++) {
                    //     if(this.Cart[i].id == id) {
                    //         currentIndex = i;
                    //     }
                    // }
                    let rightcon = this.Cart[0].subitems;
                    let idset = rightcon[2].id;
                    this.setData({
                        currentIndex,
                        leftmun,
                        rightcon,
                        idset,
                    })
                }
            });
            app.func.postPromise('/categorySku', {
              id: 385,
              offset: 0,
              length: 4,
              sort: 0,
            }).then(res=>{
              this.setData({
                goodsList3 :res[1].data
              })
            })
            wx.getSystemInfo({
              success:  (res) => {
                console.log(res.windowWidth)
                let widhtradiv= res.windowWidth*0.9
                this.setData({
                  widhtradiv,
                  White_bg:false
                })
               
              }
            })
         
},

  /**
   * 组件的方法列表
   */
  methods: {
    banner: function () {
      app.func.getPromise('/list/banner')
          .then(([code, res]) => {
              this.setData({banner: res.data});
               console.log(res.data)
          })
         
  },
  search: function () {
    wx.navigateTo({
        url: "/pages/index/search/search"
    })
},
jumpType: function (e) {
  let item = e.currentTarget.dataset.item;
  switch (item[`link_type`]) {
      case 0:
          let id = item[`category_id`];
          wx.setStorage({key: "category_id", id})
          let extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {};
          if (extConfig.category = null || extConfig.category == 0) {

              wx.navigateTo({
                  url: '/pages/index/categorysku/categorysku',
              })
          } else {
              wx.navigateTo({
                  url: '/pages/index/newcategory/newcategory?id=' + id,
              })
          }
          break;
      case 1:
          wx.navigateTo({
              url: '/pages/index/brandsku/brandsku?id=' + item['topic_id']
          })
          break;
      case 2:
          wx.navigateTo({
              url: `/pages/index/webView/webView?src=${item.link}`
          })
          break;
  }
},
brandsku: function (e) {
  let item = e.currentTarget.dataset.item;
  switch (item[`link_type`]){
    case 0:
      let id = item[`category_id`];
      // wx.setStorage({key:"ca【【【【tegory_id", id})旧
      wx.setStorageSync('category_id', id)
      let extConfig = wx.getExtConfigSync? wx.getExtConfigSync(): {} ;
      if(extConfig.category = null || extConfig.category == 0) {
        wx.navigateTo({
          url: '/pages/index/categorysku/categorysku',
        })
      } else {
        wx.navigateTo({
          url: '/pages/index/newcategory/newcategory?id=' + id,
        })
      }
      break;
    case 1:
      wx.navigateTo({
        url:'/pages/index/brandsku/brandsku?id=' + item['topic_id']
      })
      break;
    case 2:
      break;
  }
},
goCreag:function(e){
let id = e.currentTarget.dataset.id;
console.log(id);
    // wx.setStorageSync('category_id', id);
    // let extConfig = wx.getExtConfigSync? wx.getExtConfigSync(): {} ;
      wx.navigateTo({
        // url: '/pages/home/components/chachengCom/chacategory/chacategory' + id,
        url:'/pages/home/components/chachengCom/chaSearch/chaSearch?name='+id
      })
},
goSection(){
  wx.navigateTo({
    url: '/pages/index/categorysku/categorysku',
})
},
gorundt(e){
  let index = e.currentTarget.dataset.index;
  let arr = this.data.brand;
  for(let i =0;i<arr.length;i++){
    if(index ==i){
      let item = arr[i];
      switch (item[`link_type`]){
        case 0:
          let id = item[`category_id`];
          // wx.setStorage({key:"ca【【【【tegory_id", id})旧
          wx.setStorageSync('category_id', id)
          wx.switchTab({
            url:'/pages/home/components/chachengCom/chacategory/chacategory'
          })
          break;
        case 1:
          wx.navigateTo({
            url:'/pages/index/brandsku/brandsku?id=' + item['topic_id']
          })
          break;
        case 2:
          wx.navigateTo({
            url: `/pages/index/webView/webView?src=${item.link}`
        })
          break;
      }
    }
  }
  
},
gobuyit:function(e){
    var id = e.currentTarget.dataset.id;
    //旧的跳转
  /**
   * wx.navigateTo({
      url: '/pages/gifts/pages/order/order?id=' + id
    })
   *  */	
  wx.navigateTo({
    url: '/pages/cartshop/payif/payif?skuid=' + id
})
  
},

productdetail: function (e) {
  var id = e.currentTarget.dataset.id;
  wx.navigateTo({
    url: '/pages/index/productdetail/productdetail?id=' + id
  })
},

  }
})
